package com.itheima.em.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

@Getter
public enum ProviderType {

    BAIDU(1, "BAIDU", "百度地图"),
    AMAP(2, "AMAP", "高德地图"),
    QQ(3, "QQ", "腾讯地图"),
    TMAP(4, "TMAP", "天地图"),
    NONE(999, "NONE", "默认地图");

    @EnumValue
    private Integer value;
    private String name;
    private String desc;

    ProviderType(int value, String name, String desc) {
        this.value = value;
        this.name = name;
        this.desc = desc;
    }

    @Override
    public String toString() {
        return this.desc;
    }

    /**
     * <h2>根据key找出 对应的 ProviderType 对象</h2>
     */
    public static ProviderType of(Integer key) {
        Objects.requireNonNull(key);
        return Stream.of(values()).filter(bean -> bean.getValue().equals(key))
                .findFirst()
                .orElseThrow(() -> new RuntimeException("no search bean by key=" + key));
    }

}
